package com.ll.trydemo;

/**
 * @author 刘龙
 * @version 1.0
 */
public class TryCatchDetail01 {
    public static void main(String[] args) {
        try {
            String str = "123a";
            int a = Integer.parseInt(str);
            System.out.println(a);

            Person person = new Person();
            person = null;
            System.out.println(person.getName());

            // 如果try代码块可能有多个异常
            // 可以使用多个catch 分别捕获不同的异常
            // 要求子类异常写在前面,父类异常写在后面

        } catch (NullPointerException e) {
            System.out.println("空指针异常" + e.getMessage());
        } catch (NumberFormatException e) {
            System.out.println("数字格式异常" + e.getMessage());
        } catch (Exception e) {
            System.out.println("全局异常");
            e.printStackTrace();
        } finally {

        }

        System.out.println("程序继续执行");
    }
}

class Person {
    private String name;

    public String getName() {
        return name;
    }
}
